package com.ihrm.company.controller;


import com.ihrm.domain.company.Company;
import com.ihrm.common.entity.Result;
import com.ihrm.company.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/company")
//@CrossOrigin(origins = "*")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    //添加公司
    @PostMapping
    public Result addCompany(@RequestBody Company company) {
        return companyService.add(company);
    }


    //查询公司
    @GetMapping
    public Result<List<Company>> selectCompany() {
        List<Company> list = companyService.select();
        return Result.SUCCESS(list);
    }

    //根据id查询公司
    @GetMapping("/{id}")
    public Result<Company> getCompanyById(@PathVariable String id) {
        Company company = companyService.getCompanyById(id);
        return Result.SUCCESS(company);
    }

    //更新公司
    @PutMapping("/{id}")
    public Result updateCompany(@PathVariable String id, @RequestBody Company company) {
        Integer num = companyService.updateCompany(id, company);
        if(num > 0) {
            return Result.SUCCESS();
        }else {
            return Result.FAIL();
        }
    }
}
